package gui.mainFrame;

import gui.GUIController;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import testGenerator.Controller;

/**
 * Provides buttons for main GUI.
 * @author William Whitney
 */
public class TestCreatorBtnPanel extends JPanel
{
    private static final long serialVersionUID = 1L;

    private GUIController guiController;
    private Controller control;
    private JLabel actualPathLabel;

    /**
     * Default constructor.
     * @param guiControl 
     */
    public TestCreatorBtnPanel(Controller control, GUIController guiControl)
    {
        this.guiController = guiControl;
        
        //Save controller
        this.control = control;
        

        //Setup panel
        this.setLayout(new FlowLayout(FlowLayout.RIGHT));

        //Add Label with path of source code
        this.addPathLabel();
        
        //Add Buttons
        this.add(getButtons());
    }

        /**
     * Adds Label to the panel with path of source code
     */
    private void addPathLabel() {
        String actualPath = control.getSourceLoc();
        if ("".equals(actualPath)) {
            actualPath = "No file selected yet.";
        }
        //Path of actual source code Label
        actualPathLabel = new JLabel("Currently working on: " + actualPath);
        this.add(actualPathLabel);
    }
    
    private JPanel getButtons()
    {
        JPanel panel = new JPanel();
        panel.setLayout(new FlowLayout());

        //Done Button
        JButton doneBtn = new JButton("Done");
        doneBtn.addActionListener(getDoneBtnListener());
        this.add(doneBtn);

        return panel;
    }

    private ActionListener getDoneBtnListener()
    {
        return new ActionListener()
        {

            @Override
            public void actionPerformed(ActionEvent e)
            {
                guiController.saveTestCreatorTest();
                guiController.showPathEditor();
            }
        };
    }
}
